/* eslint-disable no-debugger */
// import { createContext, useContext } from 'react'
import { useContext } from 'react'
import { createContext } from 'react-activation'

const MainContext = createContext('MainContext')

const useMainContext = function () {
  return useContext(MainContext)
}

const UseCodes = function (codeKey) {
  const { codes=[] } = useContext(MainContext)
  const codeObj = codes.find((item) => item.codeKey === codeKey)
  return codeObj ? codeObj.options : []
}

const UseCodeText = function (codeKey, value) {
  const { codes } = useContext(MainContext)
  const codeObj = codes.find((item) => item.codeKey === codeKey)
  if (codeObj) {
    const option = codeObj.find((item) => item.value === value)
    return option ? option.label : value
  }
  return value
}

export { MainContext, useMainContext, UseCodes, UseCodeText }
